//数据请求插件
import axios from 'axios';
import flight from './flight';


export default function (Vue) {

  axios.defaults.baseURL = $tool.getServerUrl();
  axios.defaults.headers['onlyValidate'] = '1';
  axios.defaults.withCredentials = true;

  //axios.defaults.headers.post['content-Type'] = 'appliction/x-www-form-urlencoded';

  //添加一个请求拦截器
  /*axios.interceptors.request.use(function(config){
   //在请求发出之前进行一些操作
   return config;
   },function(err){
   //Do something with request error
   return Promise.reject(error);
   });*/

  //添加一个响应拦截器
  axios.interceptors.response.use(function (res) {
    if(res.data && res.data.isLogin == false) {
      $jump.url(window.location.origin+'/index');
      //throw 'please login first!';
    }
    return res;
  }, function (err) {
    //出错或正常响应拦截
    //return Promise.resolve('ok');
    return Promise.reject('error');
  });

  platform.axios = flight.axios = hotel.axios = train.axios = car.axios = plan.axios = common.axios =  axios;
  Vue.prototype.$flight = flight;
  Vue.prototype.axios = axios;
};
